package com.uu.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
public class ViewController {

    @GetMapping(value = {"/a"})
    public String index(HttpServletResponse response) {
        return "paysuccess";
    }

    /**
     * 返回
     * window.location.replace
     */
    @GetMapping("/bLocationReplace")
    public void redirect(HttpServletRequest request, HttpServletResponse response) {
        // 通过response向前端写一段script
        response.setContentType("text/html;charset=utf-8");
        try {
            response.getWriter().write("<script>window.location.replace(\"http://xxxhostb:8001/c\");</script>");
        } catch (Exception e) {
        }
    }

    /**
     * 重定向
     */
    @GetMapping("/bRedirect")
    public void bRedirect(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.sendRedirect("http://xxxhostb:8001/c");
    }

    /**
     * 简单提交
     */
    @GetMapping("/bPost")
    public void bPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("bPost");
        response.getWriter().write("this is a test");
    }


    @GetMapping(value = {"/c"})
    public String moa(HttpServletResponse response) {
        return "moa";
    }
}
